#include<bits/stdc++.h>
using namespace std;
int T,n;
int a[200009];
int dfs(int x,int sum,int red,int blue){
    if(x==n+1)return sum;
    int ansa=0,ansb=0;
    if(a[red]==a[x])ansa=a[x];
    if(a[blue]==a[x])ansb=a[x];
    ansa=dfs(x+1,sum+ansa,x,blue);
    ansb=dfs(x+1,sum+ansb,red,x);
    return max(ansa,ansb) ;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>T;
    while(T--){
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        cout<<dfs(1,0,0,0)<<"\n";
    }

}
